package com.patterns.memento;

/**
 * 源发器类
 * 被记录的对象为学生，当信息修改时可以回滚操作
 * @author huangke
 *
 */
public class Student {
	private String name;
	private int age;
	
	//进行备忘操作，并返回备忘操作
	public StudentMemento memento(){
		return new StudentMemento(this);
	}
	
	//进行数据恢复，将恢复到指定备忘录的值
	public void recovery(StudentMemento memento){
		this.name = memento.getName();
		this.age = memento.getAge();
	}
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		this.age = age;
	}

	@Override
	public String toString() {
		return "Student [name=" + name + ", age=" + age + "]";
	}
}
